Test the output of `cargo package`
authorAlex Crichton <alex@alexcrichton.com>
Tue, 9 Sep 2014 02:38:16 +0000 (19:38 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 16 Sep 2014 19:05:21 +0000 (12:05 -0700)
src/cargo/ops/cargo_package.rs
tests/test_cargo_package.rs

index 6abafd2824cd8396850c8e442673210ca3a39c05..3bf28597c4c8cd752f60e2cfa4f92dba91c93007 100644 (file)
@@ -42,6 +42,7 @@ fn tar(pkg: &Package, src: &PathSource, shell: &mut MultiShell,
     // Put all package files into a compressed archive
     let ar = Archive::new(encoder);
     for file in try!(src.list_files(pkg)).iter() {
+        if file == dst { continue }
         let relative = file.path_relative_from(&dst.dir_path()).unwrap();
         let relative = try!(relative.as_str().require(|| {
             human(format!("non-utf8 path in source directory: {}",
index 969a2e64749c1eb82f9633fab31039c46001c1fa..5761916e0c600675501c1c72915112e218eccdfc 100644 (file)
@@ -1,4 +1,9 @@
-use support::{project, execs};
+extern crate tar;
+extern crate flate2;
+
+use std::io::{File, MemReader};
+
+use support::{project, execs, cargo_dir, ResultTest};
 use support::{PACKAGING};
 use hamcrest::{assert_that, existing_file};
 
@@ -12,10 +17,12 @@ test!(simple {
             name = "foo"
             version = "0.0.1"
             authors = []
+            exclude = ["*.txt"]
         "#)
         .file("src/main.rs", r#"
             fn main() { println!("hello"); }
-        "#);
+        "#)
+        .file("src/bar.txt", ""); // should be ignored when packaging
 
     assert_that(p.cargo_process("package"),
                 execs().with_status(0).with_stdout(format!("\
@@ -24,4 +31,19 @@ test!(simple {
         packaging = PACKAGING,
         dir = p.url()).as_slice()));
     assert_that(&p.root().join("foo-0.0.1.tar.gz"), existing_file());
+    assert_that(p.process(cargo_dir().join("cargo")).arg("package"),
+                execs().with_status(0).with_stdout(""));
+
+    let f = File::open(&p.root().join("foo-0.0.1.tar.gz")).assert();
+    let mut rdr = flate2::reader::GzDecoder::new(f);
+    let contents = rdr.read_to_end().assert();
+    let ar = tar::Archive::new(MemReader::new(contents));
+    for f in ar.files().assert() {
+        let f = f.assert();
+        match f.filename().unwrap() {
+            "foo-0.0.1/Cargo.toml" |
+            "foo-0.0.1/src/main.rs" => {}
+            s => fail!("unexpected file: {}", s),
+        }
+    }
 })